package com.ahs.controller;


import com.ahs.pojo.Dog;
import com.ahs.pojo.User;
import com.ahs.service.DogService;
import com.ahs.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author riven zhang
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    private final UserService userService;
    private final DogService dogService;

    public UserController(UserService userService, DogService dogService) {
        this.userService = userService;
        this.dogService = dogService;
    }

    @GetMapping("fuzzySearch")
    public List<User> fuzzySearch(@RequestParam(required = false) String keyword) {
        return userService.fuzzySearch(keyword);
    }

    @PostMapping("add")
    public boolean add(@RequestBody User user) {
        return userService.save(user);
    }

    @GetMapping("age/{num}")
    public boolean subtractAge(@PathVariable("num") int num) {
        return userService.subtractAge(num);
    }

    @GetMapping("findAndy")
    public User findAndy() {
        return userService.getById(1);
    }

    @GetMapping("findDog")
    public Dog findDog() {
        return dogService.getById(1);
    }

}

